<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    let arr = [
      { label: "男", value: 1 },
      { label: "女", value: 0 },
    ];
    //使用map方法返回["男","女"]
    // let sex = arr.map(function (item, index) {
    //   return item.label;
    // });
    // console.log(sex);
    let obj = {};
    arr.forEach(function (item, index) {
      obj[item.value] = item.label;
    });
    console.log(obj);
  </script>
</html>
